#!/bin/bash
# 脚本功能：喂狗程序
# 需要在开机自启中添加
# bash /root/hardware/External_watchdog.sh >> /root/hardware/External_watchdog.log &

# 引用gpio控制模块
source /root/hardware/gpio_control_api/method3/gpio_model.sh

# GPIO3_B3=3*32+1*8+3=107
pin=107
#######################################################
# 喂狗函数
function feed_watchdog(){
    gpio_pin=$1

    gpio_outvalue 1 $gpio_pin
    # echo ">>> 高电平~~"

    sleep 2s

    gpio_outvalue 0 $gpio_pin
    # echo ">>> 低电平~~"

}

#######################################################

# 主进程
## 初始化引脚
echo "[$(date "+%Y年%m月%d日 %H时:%M分:%S秒")] feed dog start ! ~ ~"
gpio_init $pin

## 判断IO方向是否为输出
get_gpio_direction $pin
if [[ $? -eq 0 ]]; then
    # is in
    gpio_direction 1 $pin # 设置为输出模式
fi
gpio_outvalue 0 $pin # 设置为低电平

while [ 1 ]
do
    feed_watchdog $pin
    # echo "[$(date "+%Y年%m月%d日 %H时:%M分:%S秒")] feed dog is OK！~~"
    sleep 2s

done
